package com.lhd.ivos.application.controller;

import com.lhd.ivos.application.pojo.dto.ApplicationQuery;
import com.lhd.ivos.application.pojo.dto.ApplicationSaveParam;
import com.lhd.ivos.application.pojo.vo.ApplicationVO;
import com.lhd.ivos.application.service.ApplicationService;
import com.lhd.ivos.base.response.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author lhd
 * date 2024/5/24
 * @apiNote
 */
@RequestMapping("/v1/application")
@RestController
@Slf4j
public class ApplicationController {

    @Autowired
    ApplicationService applicationService;

    @PostMapping("save")
    public JsonResult saveApplication(ApplicationSaveParam  applicationSaveParam) {
        log.debug("新增用车申请信息为 = {}", applicationSaveParam);
        applicationService.save(applicationSaveParam);
        return JsonResult.ok();
    }
    @GetMapping("select")
    public JsonResult select(ApplicationQuery applicationQuery){
        log.debug("查询车辆申请单:applicationQuery={}",applicationQuery);
        List<ApplicationVO> list = applicationService.selectApplication(applicationQuery);
        return JsonResult.ok(list);
    }

    @PostMapping("cancel/{id}")
    public JsonResult cancel(@PathVariable Long id){
        log.debug("撤销申请:id={}",id);
        applicationService.cancel(id);
        return JsonResult.ok();
    }


    @PostMapping("distribute/{applicationId}/{vehicleId}")
    public JsonResult distribute(@PathVariable Long applicationId,
                                 @PathVariable Long vehicleId){
        log.debug("分配车辆:申请单编号={},车辆编号={}",applicationId,vehicleId);
        applicationService.distribute(applicationId,vehicleId);
        return JsonResult.ok();
    }

}
